package cn.edu.zafu.bigdata.x.zcy_0217;

public class ArithmeticExceptionDemo {

    public static void main(String[] args) {
        try {
            int result = divide(10, 0);
            System.out.println("结果是: " + result);
        } catch (ArithmeticException e) {
            System.out.println("错误：不能除以零！");
        }
    }

    public static int divide(int a, int b) {
        if (b == 0) {
            throw new ArithmeticException("除数不能为零");
        }
        return a / b;
    }
}

/*
public class ArithmeticExceptionDemo{
    public static void main(String[] args){
        int result=divide(2,0);
        if(result==0){
            System.out.println("不能除以0");
        }else{
            System.out.println("结果为："+result);
        }
    }

    public static int divide(int a,int b){
        if(b==0){
            return 0;
        }
        else{
            return a/b;
        }
    }
}
*/
